<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        body,
        html,
        #allmap {
            width: 100%;
            height: 100%;
            overflow: hidden;
            margin: 0;
            font-family: "微软雅黑";
        }
    </style>
    <!-- gktwARGFRZcfumx9y9vml1vntQI6cCoO -->
    <script type="text/javascript"
        src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=gktwARGFRZcfumx9y9vml1vntQI6cCoO"></script>
    <title>添加信息窗口</title>
</head>

<body>
    <div id="allmap"></div>
</body>

</html>
<script type="text/javascript">
    // 百度地图API功能
    var map = new BMapGL.Map("allmap");
    //将 显示的小圆点的数据统一放在 数组中
    var mapArr = [
        { "weidu": 22.603623645020644, "jingdu": 113.8425919730447, "title": "泽林宝安校区", "message": "这里是学习前端的课堂", "addr": "地址：新中泰6楼" },
        { "weidu": 22.549036, "jingdu": 113.947646, "title": "泽林南山校区", "message": "这里是学习前端的课堂666", "addr": "地址：国人通信大厦11楼" },
    ];


    var point = new BMapGL.Point(113.8425919730447, 22.603623645020644);
    map.centerAndZoom(point, 15);

    mapArr.forEach((item, index) => {

        var point1 = new BMapGL.Point(item.jingdu, item.weidu);
        var marker = new BMapGL.Marker(point1);  // 创建标注
        map.addOverlay(marker);              // 将标注添加到地图中
        var opts = {
            width: 200,     // 信息窗口宽度
            height: 100,     // 信息窗口高度
            title: item.title, // 信息窗口标题
            message: item.message
        }
        var infoWindow = new BMapGL.InfoWindow(item.addr, opts);  // 创建信息窗口对象 
        marker.addEventListener("click", function () {
            map.openInfoWindow(infoWindow, point); //开启信息窗口
        });
    })



</script>